//
//  IsoGridLine.cpp
//  IsoCplus
//
//  Created by 周张林 on 15/9/17.
//  显示地图网格，辅助制作
//
//

#include "IsoGridLine.h"
#include "IsoUtil.h"
#include "IsoScene.h"

USING_NS_CC;

bool IsoGridLine::init(int size ,int gridX ,int gridZ , float alpha)
{
    if(!IsoScene::init(size, gridX, gridZ)) return false;
    _alpha = alpha;
    return true;
}

void IsoGridLine::render()
{
    removeAllChildren();
    auto drawNode = DrawNode::create();
    auto lineColor = Color4F(1, 0, 0, _alpha);
    auto thick = 2;
    auto p = Vec3(0,0,0);
    
    for(int i=0;i<=_spanX;i++){
        p.x = i*_size;
        p.z = 0;
        auto startPos = IsoUtil::isoToScreen( p.x,p.y,p.z);
        p.z = _spanZ*_size;
        auto endPos = IsoUtil::isoToScreen( p.x,p.y,p.z);
        drawNode->drawSegment(Vec2(startPos.x,startPos.y), Vec2(endPos.x,endPos.y),thick, lineColor);
    }
    
    for(int i=0;i<=_spanZ;i++){
        p.z = i*_size;
        p.x = 0;
        auto startPos = IsoUtil::isoToScreen( p.x,p.y,p.z);
        p.x = _spanX*_size;
        auto endPos = IsoUtil::isoToScreen( p.x,p.y,p.z);
        drawNode->drawSegment(Vec2(startPos.x,startPos.y), Vec2(endPos.x,endPos.y),thick, lineColor);
    }
    this->addChild(drawNode);
}